<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$connection = mysql_connect('localhost', '', '');
$dbSelect = mysql_select_db('',$connection);

	$i=0;
    $species='';
	$vernacular ='';
	$breeding='';
	$order ='';
	$genus = '';
	$family = '';
	$breedingVerbarim='';
	$familyVernacular='';


	$row = 1;
	if (($handle = fopen("Master_IOC_list_v2.7.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        if($row!=1)
        {
	        for ($c=0; $c < $num; $c++) {
	          	switch($c){
					  	case 0:
					  			if($data[0]!=''){
					  				$order =$data[0];
					  			}
						break;

						case 1:
					  			if($data[1]!=''){
					  				$family = $data[1];
					  			}
						break;

						case 2:
					  			if($data[2]!=''){
					  				$familyVernacular= $data[2];
					  			}
						break;

						case 3:
					  			if($data[3]!=''){
					  				$genus = $data[3];
					  			}
						break;

						case 4:

					  				$species = $data[4];

						break;
						case 5:
					  				$vernacular = $data[5];

						break;

						case 6:
					  				$breeding = $data[6];
						break;

						case 7:
					  				$breedingVerbarim = $data[7];
						break;
					  }


		      		}

		      		if($species!=''){
						$query = sprintf("INSERT INTO `species` (`order_`, `family`, `familyVernacular`, `genus`, `species`, `vernacular`, `breeding`, `breedingVerbarim`) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')"
	      				, mysql_escape_string($order)
	      				, mysql_escape_string($family)
	      				, mysql_escape_string($familyVernacular)
	      				, mysql_escape_string($genus)
	      				, mysql_escape_string($species)
	      				, mysql_escape_string($vernacular)
	      				, mysql_escape_string($breeding)
	      				, mysql_escape_string($breedingVerbarim)

	      				);
	      			$result=mysql_query($query);
	      			//print($query);
	        	}

		 }
		 $row++;
    }
    fclose($handle);
}
